﻿using System.Collections.Generic;
using System.ComponentModel;
using EDMDesigner.Business.Util;

namespace EDMDesigner.Business.SSDL.Function
{
    public class Function : INotifyPropertyChanged, INamedElement
    {
        public SSDLContainer Container { get; internal set; }

        public bool? Aggregate { get; set; }
        public bool? BuiltIn { get; set; }
        public bool? IsComposable { get; set; }
        public bool? NiladicFunction { get; set; }
        public string Schema { get; set; }
        public string StoreName { get; set; }
        public string StoreSchema { get; set; }
        public string StoreType { get; set; }
        public string StoreFunctionName { get; set; }
        public ParameterTypeSemantics? ParameterTypeSemantics { get; set; }

        private string _name;
        public string Name
        {
            get { return _name; }
            set 
            {
                _name = value;
                OnPropertyChanged("Name");
            }
        }

        private string _returnType;
        public string ReturnType
        {
            get { return _returnType; }
            set 
            {
                _returnType = value;
                OnPropertyChanged("ReturnType");
            }
        }

        private string _commandText;
        public string CommandText
        {
            get { return _commandText; }
            set 
            {
                _commandText = value;
                OnPropertyChanged("CommandText");
            }
        }

        private List<FunctionParameter> _parameters;
        public List<FunctionParameter> Parameters
        {
            get
            {
                if (_parameters == null)
                    _parameters = new List<FunctionParameter>();
                return _parameters;
            }
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
